import * as localCache from '@comm/utils/mUtils'
import httpCore from '../../api/httpCore'
const api = new httpCore()

const state = {
  userInfo: JSON.parse(localCache.getlocalStore("userInfo")) || {},
  phoneNo: JSON.parse(localCache.getlocalStore("phoneNo")) || '',
}

const mutations = {
  SET_USER_INFO: (state, userInfo) => {
    //  保存在缓存
    if (userInfo) {
      localCache.setlocalStore('userInfo', userInfo)
    }
    state.userInfo = userInfo
  },
  SET_PHONE_NO: (state, phoneNo) => {
    if (phoneNo) {
      localCache.setlocalStore('phoneNo', phoneNo)
    }
    state.phoneNo = phoneNo
  },
  DELETE_USER_ALL: (state) =>{
    state.phoneNo = ''
    state.userInfo = ''
    localCache.removelocalStore('userInfo')
    localCache.removelocalStore('phoneNo')
  }
}

const actions = {
  setUserInfo: function ({commit}, args) {
    commit('SET_USER_INFO', args)
  },
  setPhoneNo: function ({commit}, args) {
    commit('SET_PHONE_NO', args)
  },
  deleteUserAll: function ({commit}) {
    commit('DELETE_USER_ALL')
  },
}

export default {
  state,
  actions,
  mutations
}
